// GameUI.cpp: implementation of the CGameUI class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GameUI.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGameUI::CGameUI()
{
	speed = 1;
	mpos = 0;
}

CGameUI::~CGameUI()
{

}


void CGameUI::Build()
{
	mpos -= speed;
	if(mpos < 0)	mpos += Bg->height;
	for(int i = 0; i < Bg->height; i++){
		for(int j = 0; j < Bg->width; j++){
			int r,g,b;
			r = CV_IMAGE_ELEM(CloneBg, uchar, (i + mpos)%Bg->height, j*3+0);
			g = CV_IMAGE_ELEM(CloneBg, uchar, (i + mpos)%Bg->height, j*3+1);
			b = CV_IMAGE_ELEM(CloneBg, uchar, (i + mpos)%Bg->height, j*3+2);

			CV_IMAGE_ELEM(Bg, uchar, i, j*3+0) = r;
			CV_IMAGE_ELEM(Bg, uchar, i, j*3+1) = g;
			CV_IMAGE_ELEM(Bg, uchar, i, j*3+2) = b;
		}
	}
}

void CGameUI::SetBgImage(IplImage *img)
{
	Bg = img;
	CloneBg = cvCloneImage(Bg);
}

void CGameUI::ShowBgImage()
{
	cvShowImage("window",Bg);
}

IplImage* CGameUI::GetNowBgImage()
{
	return Bg;
}
